/*
 *
 * Copyright (c) 2022 The Raptor Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef RAPTOR_LITE_IMPL_ENGINE_H_
#define RAPTOR_LITE_IMPL_ENGINE_H_

#include "raptor-lite/utils/status.h"
#include "raptor-lite/utils/ref_counted_ptr.h"

namespace raptor {

class Acceptor;
class Connector;
class Container;
class Property;

class EngineImpl;
class Engine final : public RefCounted<Engine, NonPolymorphicRefCount> {

public:
    explicit Engine(EngineImpl *impl);
    ~Engine();

    /*
     * Property:
     *   1. kAcceptorHandler (required)
     */
    raptor_error CreateAcceptor(const Property &p, Acceptor **out);
    void DestroyAcceptor(Acceptor *);

    /*
     * Property:
     *   1. kConnectorHandler (required)
     *   2. kTcpUserTimeoutMs (optional, default:0)
     */
    raptor_error CreateConnector(const Property &p, Connector **out);
    void DestroyConnector(Connector *);

    /*
     * Property:
     *   1. kProtocolHandler            (optional, default: nullptr)
     *   2. kMessageHandler             (required)
     *   3. kHeartbeatHandler           (optional, default: nullptr)
     *   4. kEndpointClosedHandler      (optional, default: nullptr)
     *   5. kRecvSendThreads            (optional, default: 1)
     *   6. kCoreEventThreads           (optional, default: 1)
     *   7. kInitContainerSize          (optional, default: 128)
     *   8. kMaxContainerSize           (optional, default: 8192)
     *   9. kCheckReceivingInterval     (optional, default: false)
     *  10. kMaxReceivingInterval       (optional, default: 300000)
     */
    raptor_error CreateContainer(const Property &p, Container **out);
    void DestroyContainer(Container *);

private:
    EngineImpl *impl_;
};

} // namespace raptor

using RaptorEngine = raptor::RefCountedPtr<raptor::Engine>;
#define RAPTOR_ENGINE_NULL nullptr

#endif // RAPTOR_LITE_IMPL_ENGINE_H_
